package com.untrance.shop.core.builder.vo;

import com.google.appengine.api.datastore.Key;
import com.untrance.shop.common.utils.JpaUtils;
import com.untrance.shop.common.vo.ProductDetailsVO;
import com.untrance.shop.common.vo.ProductVO;
import com.untrance.shop.model.Product;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;

/**
 * @author eugene zadyra
 */
public class ProductDetailsVOBuilder extends AbstractVOBuilder<Product, ProductDetailsVO> {

	public ProductDetailsVOBuilder() {
	}

	@Override
	protected ProductDetailsVO transform(Product product) {
		ProductDetailsVO productDetailsVO = new ProductDetailsVO();
		ProductVO productVO = new ProductVOBuilder().createVO(product);
		BeanUtils.copyProperties(productVO, productDetailsVO);
		if(product.getAdditionalImages() !=null){
			productDetailsVO.setImageIds(new ArrayList<String>());
			for(Key key: product.getAdditionalImages()){
				productDetailsVO.getImageIds().add(JpaUtils.getString(key));
			}
		}
		productDetailsVO.setLongDescription(product.getLongDescription());
		productDetailsVO.setCategoryKey(JpaUtils.getString(product.getCategoryKey()));
		return productDetailsVO;
	}
}
